import { requestClient } from '#/api/request';

/**
 * 菜单数据类型
 */
export interface Menu {
  id: number;
  menuName: string;
  path: string;
  component: string;
  status: string; // "0"=正常，"1"=停用
  perms: string; // 权限标识
  parentId: number;
  children?: Menu[];
  createTime?: string;
  updateTime?: string;
}

/**
 * 菜单列表查询参数
 */
export interface MenuListParams {
  menuName?: string;
  status?: string;
  perms?: string;
  parentId?: number;
}

/**
 * 菜单表单数据
 */
export interface MenuFormData {
  id?: number;
  menuName: string;
  path: string;
  component: string;
  status: string;
  perms: string;
  parentId: number;
}

/**
 * 菜单树节点
 */
export interface MenuTreeNode {
  id: number;
  menuName: string;
  children?: MenuTreeNode[];
}

/**
 * 角色菜单树数据
 */
export interface RoleMenuTreeData {
  checkedKeys: number[];
  menuTree: MenuTreeNode[];
}

/**
 * 获取菜单列表
 */
export async function getMenuListApi(params?: MenuListParams) {
  return requestClient.get<Menu[]>('/menu/list', { params });
}

/**
 * 获取菜单树
 */
export async function getMenuTreeApi() {
  return requestClient.get<MenuTreeNode[]>('/menu/treeselect');
}

/**
 * 获取菜单详情
 */
export async function getMenuDetailApi(id: number) {
  return requestClient.get<Menu>(`/menu/${id}`);
}

/**
 * 新增菜单
 */
export async function createMenuApi(data: MenuFormData) {
  return requestClient.post<Menu>('/menu', data);
}

/**
 * 修改菜单
 */
export async function updateMenuApi(data: MenuFormData) {
  return requestClient.put<Menu>('/menu', data);
}

/**
 * 删除菜单
 */
export async function deleteMenuApi(id: number) {
  return requestClient.delete(`/menu/${id}`);
}

/**
 * 获取角色菜单树
 */
export async function getRoleMenuTreeApi(roleId: number) {
  return requestClient.get<RoleMenuTreeData>(`/menu/roleMenuTreeselect/${roleId}`);
}

/**
 * 根据父菜单ID获取菜单
 */
export async function getMenusByParentIdApi(parentId: number) {
  return requestClient.get<Menu[]>(`/menu/listByParentId/${parentId}`);
} 
